// studentMine/tab/deliver/deliver.js
import {
    ajaxPost,
    showToast,
} from '../../../utils/util'
let app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        page: 1,
        limit: 10,
        tabList: [{
                title: '全部',
                value: 0,
            },
            {
                title: '未处理',
                value: 1,
            },
            {
                title: '有意向',
                value: 2,
            },
            {
                title: '不合适',
                value: 3,
            },

        ],
        tabVal: 0,
        listSource: [],
        noGet: false,

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.setData({
            noGet: false,
            listSource: [],
            page: 1,
        })
        this.getList()
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        this.getList()

    },
    // ======================》》》》》》》》 操作逻辑  《《《《《《===============
    /**
     * tab切换以及重新获取数据
     * @param {*} e 参数
     */
    tabClick(e) {
        const index = e.target.dataset.index
        if (this.data.tabVal != index) {
            this.setData({
                noGet: false,
                listSource: [],
                page: 1,
                tabVal: index
            })
            this.getList()
        }
    },
    /**
     *   数据获取
     */
    getList() {
        if (this.data.noGet) {
            return;
        }
        let data = {
            token: wx.getStorageSync('token'),
            source: 0,
            position_id: 0,
            status: this.data.tabVal,
            page: this.data.page++,
            limit: this.data.limit,
        }
        ajaxPost('/company/myresumelist', data, res => {
            if (res.code == 0) {
                console.log(this.data.page - 1);
                if (res.data.list.length < this.data.limit) {
                    if (res.data.list.length == 0) {
                        this.setData({
                            noGet: true,
                        })
                        return;
                    }
                    console.log(this.data.listSource);
                    this.setData({
                        listSource: this.data.listSource.concat(res.data.list),
                        noGet: true,
                    })
                    console.log(this.data.listSource);
                    return;

                }
                if (this.data.page - 1 > 1) {
                    this.setData({
                        listSource: this.data.listSource.concat(res.data.list)
                    })

                } else {
                    this.setData({
                        listSource: res.data.list
                    })
                }

            } else {
                showToast('text', res.msg)
            }
        })
    },
    /** 
     * 进入详情
     */
    goCont(e) {
        console.log(e);
        wx.navigateTo({
            url: `/pages/enterprise/listCont/listCont?id=${e.currentTarget.dataset.id}&aid=${e.currentTarget.dataset.aid}`
        })

    },

})